//
//  SideBarViewController.m
//  
//
//  Created by qkong on 15/6/15.
//
//

#import "SideBarLeftViewController.h"
#import "FunctionTableViewCell.h"
#import "EquipmentListViewController.h"
typedef enum{
    kEquipList = 0, //设备列表
    kUserSetting,   //用户设置
    kFeedBack,      //意见反馈
    kAbout,         //关于软件
    kTripGuide      //出行指南
} SideBarList;
@interface SideBarLeftViewController ()

@end

@implementation SideBarLeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpFunctionTable];
}


- (void)setUpFunctionTable{
    self.functionTableView.delegate = self;
    self.functionTableView.dataSource = self;
    self.functionTableView.scrollEnabled = NO;
    self.functionTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.functionTableView.tableFooterView = [[UIView alloc]init];
}


#pragma mark -
#pragma mark tableview数据
- (NSArray *)getImages{
    return @[@"ic_drawer_appstore_normal.png",
             @"ic_drawer_setting_normal.png",
             @"ic_drawer_message_normal.png",
             @"ic_drawer_feedback_normal.png",
             @"ic_drawer_search_normal.png"];
}

- (NSArray *)getFunctionNames{
    return @[@"设备列表",
             @"用户设置",
             @"意见反馈",
             @"关于软件",
             @"出行指南"];
}

#pragma mark -
#pragma mark table view delegate
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithWhite:0.122 alpha:1.000];
}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithWhite:0.169 alpha:1.000];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self getFunctionNames].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"FunctionCell";
    FunctionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[FunctionTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    NSUInteger index = indexPath.row;
    [cell addSingleLineToTop];
    if (index == [self getImages].count-1) {
        [cell addSingleLineToBottom];
    }
    [cell setBackgroundColor:[UIColor colorWithWhite:0.169 alpha:1.000]];
    [cell setCellWithImageName:[self getImages][index] andFunctionName:[self getFunctionNames][index]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        //设备列表
        case kEquipList:
        {
            EquipmentListViewController *equitmentListVC = [[EquipmentListViewController alloc]initWithNibName:@"EquipmentListViewController" bundle:nil];
            [self presentViewController:equitmentListVC animated:YES completion:nil];
        }
            break;
        //用户设置
        case kUserSetting:
        {
            
        }
            break;
        //意见反馈
        case kFeedBack:
        {
            
        }
            break;
        //关于软件
        case kAbout:
        {
            
        }
            break;
        //出行指南
        case kTripGuide:
        {
            [self openTripGuideWebSite];
        }
            break;
    }
}

//出行指南网站
- (void)openTripGuideWebSite{
    [[UIApplication sharedApplication]openURL:[[NSURL alloc]initWithString:TRIP_GUID_URL]];
}


@end
